// packageA/valueAddedTax/valueAddedTax.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        picPath: app.globalData.picPath,
        tipText: app.globalData.tipText,// 顶部提示语
        heMoney: '',// 合同金额
        diMoney: '',// 费用票回抵金额
        navList: [],//底部导航栏
        showPop: false,
        list: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var navList = app.globalData.navList, nowPage = '/' + this.is;
        navList = navList.filter(item => {
            return item.path != nowPage
        })
        this.setData({
            navList
        })
        console.log(this.data);
    },


    toNav(e) {
        console.log(e);
        var path = e.currentTarget.dataset.nav.path;
        console.log(path);
        if (path == '') {
            wx.showToast({
                title: '抱歉，功能暂未开通',
                icon: 'none'
            })
            return
        }
        wx.redirectTo({
            url: path,
        })
    },


    closeHandle() {
        this.setData({
            showPop: false
        })
    },
    checkHandle() {
        if (this.data.heMoney == '') {
            wx.showToast({
                title: '请输入合同金额',
                icon: 'none'
            })
            return
        }
        if (this.data.diMoney == '') {
            wx.showToast({
                title: '请输入费用票回抵金额',
                icon: 'none'
            })
            return
        }
        console.log(this.data);

        var that = this;
        var url = app.globalData.url + "tool/countTax",
            data = {
                contract: that.data.heMoney,
                deduction: that.data.diMoney,
            }, list = [];
        wx.showLoading({
            title: '',
        })
        app.wxRequest(url, data, res => {
            if (res.flag) {
                console.log(res.data);
                list = [
                    {
                        text: '合同金额',
                        lv: '税点13%',
                        money: '￥' + Number(that.data.heMoney).toLocaleString(),
                    },
                    {
                        text: '不含税金额',
                        lv: '合同金额 / 1.13',
                        money: '￥' + Number(res.data.buhanshuiNum).toLocaleString(),
                    },
                    {
                        text: '增值税',
                        lv: '合同金额 / 1.13*0.13',
                        money: '￥' + Number(res.data.zengzhishuiNum).toLocaleString(),
                    },
                    {
                        text: '城市维护建设税',
                        lv: '增值税 * 7%',
                        money: '￥' + Number(res.data.cityNum).toLocaleString(),
                    },
                    {
                        text: '教育附加税',
                        lv: '增值税 * 3%',
                        money: '￥' + Number(res.data.educationNum).toLocaleString(),
                    },
                    {
                        text: '地方教育附加税',
                        lv: '增值税 * 2%',
                        money: '￥' + Number(res.data.df_educationNum).toLocaleString(),
                    },
                    {
                        text: '防洪基金',
                        lv: '不含税金额 * 万分之六',
                        money: '￥' + Number(res.data.fanghongNum).toLocaleString(),
                    },
                    {
                        text: '印花税',
                        lv: '合同金额 * 万分之五',
                        money: '￥' + Number(res.data.yinhuaNum).toLocaleString(),
                    },
                    {
                        text: '工会经费',
                        lv: '',
                        money: '￥' + 0,
                    },
                    {
                        text: '残疾人保障金',
                        lv: '',
                        money: '￥' + 0,
                    },
                    {
                        text: '环境保护税',
                        lv: '',
                        money: '￥' + 0,
                    },
                    {
                        text: '增值税小计',
                        lv: '',
                        money: '￥' + Number(res.data.zzsCountNum).toLocaleString(),
                    },
                    {
                        text: '费用票回抵金额',
                        lv: '',
                        money: '￥' + Number(that.data.diMoney).toLocaleString(),
                    },
                    {
                        text: '企业所得',
                        lv: '',
                        money: '￥' + Number(res.data.qiyesuodeNum).toLocaleString(),
                    },
                    {
                        text: '税金',
                        lv: '',
                        money: '￥' + Number(res.data.shuijinNum).toLocaleString(),
                    },
                    {
                        text: '税率快速汇算',
                        lv: '',
                        money: res.data.shuilvNum,
                    },
                ]

                wx.showToast({
                    title: '计算成功',
                    icon: 'none'
                })
                that.setData({
                    showPop: true,
                    list
                })
                wx.hideLoading()
            }
        }, err => { })


        this.setData({
            showPop: true
        })
    },
    resHandle() {
        wx.showModal({
            title: '提示',
            content: '是否重置信息',
            complete: (res) => {
                if (res.cancel) {
                }
                if (res.confirm) {
                    this.setData({
                        heMoney: '',
                        diMoney: '',
                    })
                }
            }
        })
    },
    inputHandle(e) {
        var str = e.currentTarget.dataset.str
        this.setData({
            [str]: e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})